package com.itheima.Controller;

import com.itheima.Pojo.Punishment;
import com.itheima.Pojo.Result;
import com.itheima.Service.PunishmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT,
        RequestMethod.DELETE, RequestMethod.OPTIONS })
@RestController
@RequestMapping("/punishment")
public class pnishmentController {
    @Autowired
    PunishmentService punishmentService;

    @GetMapping
    public Result getAllPunishment() {
        log.info("获取所有punishment");
        List<Punishment> list = punishmentService.getAllPunishment();
        return Result.success(list);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        log.info(">>>> 进入删除方法，ID: {}", id);
        punishmentService.deleteById(id);
        log.info("<<<< 删除方法执行完成");
        return Result.success();
    }

    @PostMapping
    public Result addPunishment(@RequestBody Punishment punishment) {
        log.info("添加punishment");
        punishmentService.addPunishment(punishment);
        return Result.success();
    }

    @PutMapping
    public Result updateById(@RequestBody Punishment punishment) {
        log.info("修改punishment");
        punishmentService.updateById(punishment);
        return Result.success();
    }

}
